//
//  PanelInstalledESCImageCell.swift
//  GreenDeal
//
//  Created by Moennig Q on 14/2/2023.
//

import UIKit
import SnapKit
import SDWebImage
class PanelInstalledESCImageCell: TableViewCell {
    let seqNoLabel = ContentLabel()
    let escImageView = UIImageView()
    lazy var activityView: UIActivityIndicatorView = {
        let activityView = UIActivityIndicatorView()
        
        return activityView
    }()
    override func setUpviews() {
        //seqNoLabel
        self.contentView.addSubview(seqNoLabel)
        seqNoLabel.snp.makeConstraints { make in
            make.top.left.equalToSuperview()
            make.width.height.greaterThanOrEqualTo(0)
        }
        //escImageView
        escImageView.contentMode = .scaleAspectFit
        self.contentView.addSubview(escImageView)
        escImageView.snp.makeConstraints { make in
            make.top.equalTo(seqNoLabel.snp.bottom).offset(4)
            make.left.right.equalToSuperview()
            make.height.equalTo(260)
            make.bottom.equalTo(-12)
        }
        // 停止后，隐藏菊花
        activityView.hidesWhenStopped = true
        //Style: whiteLarge比较大的白色环形进度条;white白色环形进度条;gray灰色环形进度条
        activityView.style = UIActivityIndicatorView.Style.white
        self.contentView.addSubview(activityView)
        activityView.snp.makeConstraints { (make) in
            make.center.equalTo(escImageView)
        }
    }
    func setData(_ imagePath: String, index: Int){
        self.seqNoLabel.text = "\(index + 1)"
        if imagePath.contains("http") {//来自服务器
            //
            guard let url = URL(string: imagePath) else {
                return
            }
            self.activityView.startAnimating()
            self.escImageView.sd_setImage(with: url, placeholderImage: UIImage(named: "installation_detail_panelnumber_list_loadfaild"), options: [SDWebImageOptions.scaleDownLargeImages]) { image, error, cashtype, url in
                self.activityView.stopAnimating()
            }
        }
    }
}
